package com.serv.test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

import com.jfinal.kit.JsonKit;
import com.serv.util.annotation.Api;

interface Intr {
	String inv(String a,String b);
}

@Api("哈哈哈")
public class Lambda {
	public static void main(String[] args) {
//		Intr i = (a,b)->a+b;
//		System.out.println(i.inv("aa","bb"));
		System.out.println(String.format("%03d",1));
	}
	
	//创建线程
	//原写法
	public static void createTd() {
		Thread td = new Thread(new Runnable() {
			
			@Override
			public void run() {
				System.out.println("hello word......");
			}
		});
		
		td.start();
	}
	
	//创建线程
	//lambda写法
	public static void createTd1(){
		Thread td = new Thread(()->System.out.println("hello word......"));
		td.start();
	}
	
	//排序
	//原写法
	public static void sort() {
		List<String> list = Arrays.asList(new String[]{"b","c","a"});
		Collections.sort(list,new Comparator<String>() {

			@Override
			public int compare(String str1, String str2) {
				return str1.compareTo(str2);
			}
			
		});
		System.out.println(JsonKit.toJson(list));
	}
	
	//lambda写法
	public static void sort1(){
		List<String> list = Arrays.asList(new String[]{"b","c","a"});
		Collections.sort(list,(str1,str2)->str1.compareTo(str2));
		System.out.println(JsonKit.toJson(list));
	}
	
	//转换成小写
	//原写法
	public static void toLowerCase(){
		List<String> proNames = Arrays.asList(new String[]{"Ni","Hao","Lambda"});
		
		List<String> lowerCaseNames = new ArrayList<String>();
		for(String str: proNames) {
			lowerCaseNames.add(str.toLowerCase());
		}
		
		System.out.println(lowerCaseNames);
	}
	
	//lambda写法
	public static void toLowerCase1(){
		List<String> proNames = Arrays.asList(new String[]{"Ni","Hao","Lambda"});
		
		List<String> lowerCaseNames = proNames.stream().map(name->name.toLowerCase()).collect(Collectors.toList());
		System.out.println(lowerCaseNames);
	}
}
